package com.zdkj.subway.check.util;

import com.zdkj.admin.api.entity.SysUser;
import com.zdkj.common.security.service.PigxUser;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserInfo {

    /**
     * 用户名
     * @return
     */
    public static String getUserName(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return  ((PigxUser) principal).getUsername();
        }
        return "";
    }

    /**
     * 用户密码
     * @return
     */
    public static String getPassword(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return ((PigxUser) principal).getPassword();
        }
        return "";
    }

    /**
     * 用户id
     * @return
     */
    public static Integer getId(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return ((PigxUser) principal).getId();
        }
        return 0;
    }

    /**
     * 用户部门id
     * @return
     */
    public static Integer getDeptId(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return ((PigxUser) principal).getDeptId();
        }
        return 0;
    }

    /**
     * 用户部门id
     * @return
     */
    public static String getUserCode(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return ((PigxUser) principal).getUserCode();
        }
        return "";
    }

    /**
     * 用户名字
     * @return
     */
    public static String getName(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof PigxUser) {
            return ((PigxUser) principal).getNikeName();
        }
        return "";
    }
}
